feat(chart): enhance margin calculations for axes in line/bar chart c…#161
feat(chart): enhance margin calculations for axes in line/bar chart c…#161rmojica-godaddy wants to merge 17 commits intomainfrom
Conversation
|
|
/approve-screenshots |
📸 Updating screenshots... View workflow run |
📚 Storybook PreviewPreview URL: https://godaddy.github.io/antares/pr-161/ Preview will be automatically deleted when this PR is closed. |
Docs Site PreviewPreview URL: https://godaddy.github.io/antares/pr-161-site/ Preview will be automatically deleted when this PR is closed. |
🎉 Successfully updated and committed screenshots! |
…arChart and LineChart
…verflow detection
📸 Updating screenshots... View workflow run |
🎉 Successfully updated and committed screenshots! |
0909960 to
4efaa00
Compare
📸 Updating screenshots... View workflow run |
🎉 Successfully updated and committed screenshots! |
There was a problem hiding this comment.
Pull request overview
Adds a new useScrollableXYChart hook to centralize axis-driven margin/size calculations for scrollable visx XY charts, and updates Line/Bar charts to use it (including improved RTL + vertical-label behavior).
Changes:
- Introduces
useScrollableXYChart(with DOM measurement helpers, Storybook doc, and browser tests). - Replaces LineChart’s old container/margin hook with
useScrollableXYChartand adds a sharedgetXLabelVerticalPropshelper. - Updates BarChart to use the new hook, simplifies margin handling (removes
getEffectiveMargin), and adds RTL controls to the playground/story.
Reviewed changes
Copilot reviewed 16 out of 48 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/@godaddy/antares/components/chart/utils.ts | Adds shared getXLabelVerticalProps helper for vertical X tick labels (LTR/RTL). |
| packages/@godaddy/antares/components/chart/use-scrollable-xy-chart/use-scrollable-xy-chart.stories.tsx | Adds Storybook story entry for the new hook. |
| packages/@godaddy/antares/components/chart/use-scrollable-xy-chart/test/use-scrollable-xy-chart.browser.test.tsx | Adds browser tests for sizing, scrolling, and pointermove re-dispatch behavior. |
| packages/@godaddy/antares/components/chart/use-scrollable-xy-chart/test/chart-container-margins.browser.test.tsx | Adds unit-style browser tests for margin measurement helpers. |
| packages/@godaddy/antares/components/chart/use-scrollable-xy-chart/src/index.tsx | Implements the new hook (axis observers + rAF batching + logical→physical margin mapping). |
| packages/@godaddy/antares/components/chart/use-scrollable-xy-chart/src/chart-container-margins.ts | Adds DOM traversal/measurement helpers for axis-derived margins. |
| packages/@godaddy/antares/components/chart/use-scrollable-xy-chart/examples/auto-layout.tsx | Adds an example used by Storybook/tests to validate hook outputs. |
| packages/@godaddy/antares/components/chart/use-scrollable-xy-chart/README.mdx | Documents the hook’s inputs/outputs and behavior. |
| packages/@godaddy/antares/components/chart/line-chart/src/use-chart-container.ts | Removes the old per-chart container/margin hook. |
| packages/@godaddy/antares/components/chart/line-chart/src/index.tsx | Migrates LineChart to useScrollableXYChart and uses the new vertical-label helper. |
| packages/@godaddy/antares/components/chart/bar-chart/src/utils.ts | Removes RTL margin swapping helper; assumes margins are already physically mapped. |
| packages/@godaddy/antares/components/chart/bar-chart/src/use-bar-chart.ts | Stops computing effectiveMargin; uses margin directly. |
| packages/@godaddy/antares/components/chart/bar-chart/src/index.tsx | Migrates BarChart to useScrollableXYChart, updates vertical label props and margin usage. |
| packages/@godaddy/antares/components/chart/bar-chart/src/index.module.css | Removes CSS-based vertical label rotation rules (now handled via tickLabelProps). |
| packages/@godaddy/antares/components/chart/bar-chart/examples/bar-chart-playground.tsx | Adds RTL toggle via RTLProvider. |
| packages/@godaddy/antares/components/chart/bar-chart/bar-chart.stories.tsx | Adds Storybook control/default for the new RTL playground toggle. |
| packages/@godaddy/antares/components/chart/line-chart/test/screenshots/* | Updates visual test screenshots to reflect the new layout behavior. |
| packages/@godaddy/antares/components/chart/bar-chart/test/screenshots/* | Updates visual test screenshots to reflect the new layout behavior. |
….tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
📸 Updating screenshots... View workflow run |
✅ No screenshot changes detected. Screenshots are already up to date. |
📸 Updating screenshots... View workflow run |
🎉 Successfully updated and committed screenshots! |
Summary
Replaces the per-component margin/sizing logic in
LineChartandBarChartwith a single shared
useScrollableXYCharthook that measures the renderedaxes and returns the margins, content-sized width/height, scroll offsets, and
label orientation the chart should use. Fixes clipped outer tick labels,
mis-sized scroll regions when X-labels rotate, and broken layouts in RTL.
Changes Made
useScrollableXYCharthook (with README, story, example, and tests)and adopted it in both
LineChartandBarChart.with hysteresis so the layout doesn't oscillate.
labels need more room than the viewport.
xLabelsOrientation: 'auto'rotates X labels vertical when they wouldn'tfit, with a shared helper that mirrors the rotation in RTL.
requestAnimationFrameand skipno-op updates.
line-chart/use-chart-container.tsandBarChart'sgetEffectiveMarginswap.Test Plan
chart-container-marginsanduseScrollableXYChart(LTR + RTL,hysteresis, scroll behavior).
LineChartandBarChartbrowser tests for the new margin behavior.Storybook.
Checklist
npm run changesetif this affects packages)